﻿workflow Start-RemoteRegistry
{
    $computers=(Get-ADComputer -Filter {(name -notlike "*v-*")}).Name | Sort-Object 

    foreach -Parallel($computer in $computers)
    {
        InlineScript 
        {
            $connectionTest=Test-Connection -Count 1 -ComputerName $Using:computer -ErrorAction SilentlyContinue
            if($connectionTest)
            {
                Write-Output "Checking Remote Registry on $Using:computer..."
                $serviceState=Get-Service -ComputerName $Using:computer -Name RemoteRegistry -ErrorAction SilentlyContinue
                if($serviceState.Status -eq "Stopped")
                {
                    Write-Output "Starting service on $Using:computer..."
                    Get-Service -ComputerName $Using:computer -Name RemoteRegistry -ErrorAction SilentlyContinue | Start-Service -ErrorAction SilentlyContinue
                    Write-Output "Done!"
                }
                elseif($serviceState.Status -eq "Running")
                {
                    Write-Output "Service is running on $Using:computer"
                }
                else
                {
                    Write-Output "Service is in"$serviceState.Status"on"$Using:computer
                }
            }
            else
            {
                Write-Output "Cannot reach $Using:computer"
            }
        }
    }
}

Start-RemoteRegistry